package cn.lanqiao.facelogin.controller;

import cn.lanqiao.facelogin.BaiDuFace.FaceSearch;
import cn.lanqiao.facelogin.BaiDuFace.JSONDataReturnValue;
import cn.lanqiao.facelogin.domain.JsonResult;
import cn.lanqiao.facelogin.domain.ResParameter;
import cn.lanqiao.facelogin.domain.Result;
import cn.lanqiao.facelogin.service.FaceService;
import cn.lanqiao.facelogin.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/face")
@Api(tags = "人脸业务")
@RestController
public class FaceController {
    @Autowired
    private LoginService loginService;
    @Autowired
    private FaceService faceService;

    @PostMapping("/facelogin")
    @ApiOperation("人脸登录")
    @ApiImplicitParam(name = "base64", value = "图片编码", required = true)
    public Object faceRecognition(String base64) throws Exception {
        JsonResult jsonResult = JSONDataReturnValue.m1(FaceSearch.m1(base64));
        if (jsonResult.isResult()) {
            String token = faceService.faceTokenObtainTelSaveJwt(jsonResult.getJson());
            return new Result(true, ResParameter.LOGIN_SUCCESS_CODE, ResParameter.FACE_DETECT_SUCCESS, token+"&"+jsonResult.getJson());
        }
        return new Result(false, ResParameter.LOGIN_SUCCESS_CODE, ResParameter.FACE_DETECT_FAIL, null);
    }

    @PostMapping("/faceDataUpdate")
    @ApiOperation("人脸更新")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "base64", value = "图片编码", required = true),
            @ApiImplicitParam(name = "tel", value = "电话号", required = true),
    })
    public Result faceDataUpdate(String base64, String uuid) throws Exception {
        return faceService.faceUpdate(base64, uuid);
    }
}
